<?php
// No directAcces
defined( '_AppBackMiage' ) or die( 'Restricted access' );
if(isAdministrateur ()){
    include_once (DS."backoffice/include/header.php");
    include_once( DS."backoffice/include/toppanel_administration.php");

    $listeDocumentAdministratif = Options::getListDocumentAdministratif();
    ?>
    <div id="wrapper">
        <div id="content">
            <div id="rightnow">
                <?php
                $title = "Liste des documents administratifs";
                $add = '<a href="' . URL . 'index.php?m=admin_administration_doc_administratifs_add" class="add">Ajouter un document</a>';
                ?>
    
                <h3 class="reallynow">
                    <span><?php echo $title; ?></span>
                    <?php echo $add;?>
                    <br />
                </h3>

                <?php
//SUPRESSION
                if (isset($_GET['delete']) && !empty($_GET['delete'])) {
                    $option = new Options($_GET['delete']);
                    $yes = '<a href="' . URL . 'index.php?m=admin_administration_doc_administratifs_list&delete='.$option->getIdOptions().'&confirm=ok">Oui</a>';
                    $no =  '<a href="' . URL . 'index.php?m=admin_administration_doc_administratifs_list">Non</a>';
                    if (isset($_GET['confirm']) && !empty($_GET['confirm'])) {
                        if ($_GET['confirm'] === "ko") {
                            ?>
                            <div align="center">
                                <p class="youhave" >
                                    &Ecirc;tes vous certain de vouloir supprimer "<?php echo $option->getKeyOptions(); ?>" ?
                                    <br/>

                                        <div class="lien" >
                                            <?php echo $yes; ?>
                                        </div>

                                        <div class="lien">
                                            <?php echo $no; ?>
                                        </div>

                                </p>
                            </div>
                            <?php
                        }
                        else {
                            $option->deleteOption();
                            unlink($option->getValueOptions());
                            $listeDocumentAdministratif = Options::getListDocumentAdministratif();
                            ?>
                            <p class="youhave">

                            <table>
                                <thead>
                                    <tr>
                                        <th>
                                            Nom du document
                                        </th>
                                        <th>
                                            Action
                                        </th>
                                    </tr>
                                </thead>


                                <tbody>
                                                <?php
                                foreach($listeDocumentAdministratif as $document){
                                    $deleteURL = URL."/index.php?m=admin_administration_doc_administratifs_list&delete=".$document->IdOptions."&confirm=ko";

                                    ?>
                                    <tr>
                                        <td>
                                            <label for="administration"><?php echo stripslashes($document->KeyOptions);?></label>
                                        </td>
                                        <td class="a-center">
                                            <a href="<?php echo $document->ValueOptions; ?>" target="blank">
                                                <img src="<?php echo STYLEBK; ?>img/icons/magnifier.png" title="Afficher document" width="16" height="16" />
                                            </a>
                                            <a href="<?php echo $deleteURL ?>">
                                                <img src="<?php echo STYLEBK; ?>img/icons/cross.png" title="Supprimer document" width="16" height="16" />
                                            </a>

                                        </td>
                                    </tr>
                                <?php
                                }
                                ?>
                                </tbody>
                            </table>

                            </p>
                        <?php
                        }
                    }
                }
//PAGE NORMALE
                else {
                    ?>
                    <p class="youhave">
                    <table>
                        <thead>
                            <tr>
                                <th>
                                    Nom du document
                                </th>
                                <th>
                                    Action
                                </th>
                            </tr>
                        </thead>


                        <tbody>
                                        <?php
                        foreach($listeDocumentAdministratif as $document){
                            $deleteURL = URL."/index.php?m=admin_administration_doc_administratifs_list&delete=".$document->IdOptions."&confirm=ko";
                            ?>
                            <tr>
                                <td>
                                    <label for="administration"><?php echo stripslashes($document->KeyOptions);?></label>
                                </td>
                                <td class="a-center">
                                    <a href="<?php echo $document->ValueOptions; ?>" target="blank">
                                        <img src="<?php echo STYLEBK; ?>img/icons/magnifier.png" title="Afficher document" width="16" height="16" />
                                    </a>
                                    <a href="<?php echo $deleteURL ?>">
                                        <img src="<?php echo STYLEBK; ?>img/icons/cross.png" title="Supprimer document" width="16" height="16" />
                                    </a>

                                </td>
                            </tr>
                        <?php
                        }
                        ?>
                        </tbody>
                    </table>

                    </p>
                <?php
                }
                ?>
            </div>
        </div>

    <?php
    include_once (DS."backoffice/include/sidebar.php");
    include_once (DS."backoffice/include/footer.php");
}
else
{
    redirectTo(URLBACK);
}
?>